ayuta.namespace("ayuta.logging");

ayuta.logging.Level = {
    OFF: 0,
    ERROR: 1,
    WARN: 2,
    INFO: 3,
    DEBUG: 4
};
ayuta.logging.Logger = new ayuta.Class({
    initialize: function(category, level) {
        this.category = category;
        this.level = level || ayuta.logging.Level.OFF;
    },
    debug: function() {
        if (this.level >= ayuta.logging.Level.DEBUG)
            this._log(ayuta.logging.Level.DEBUG, this._args2Array(arguments));
    },
    info: function() {
        if (this.level >= ayuta.logging.Level.INFO)
            this._log(ayuta.logging.Level.INFO, this._args2Array(arguments));
    },
    warn: function() {
        if (this.level >= ayuta.logging.Level.WARN)
            this._log(ayuta.logging.Level.WARN, this._args2Array(arguments));
    },
    error: function() {
        if (this.level >= ayuta.logging.Level.ERROR)
            this._log(ayuta.logging.Level.ERROR, this._args2Array(arguments));
    },
    debugException: function(error) {
        if (this.level >= ayuta.logging.Level.DEBUG)
            this._logException(ayuta.logging.Level.DEBUG, e);
    },
    infoException: function(error) {
        if (this.level >= ayuta.logging.Level.INFO)
            this._logException(ayuta.logging.Level.INFO, e);
    },
    warnException: function(error) {
        if (this.level >= ayuta.logging.Level.WARN)
            this._logException(ayuta.logging.Level.WARN, e);
    },
    errorException: function(error) {
        if (this.level >= ayuta.logging.Level.ERROR)
            this._logException(ayuta.logging.Level.ERROR, e);
    },
    _log: function(level, args) {
    },
    _logException: function(level, e) {
    },
    _args2Array: function(args) {
        var results = [];
        for (var i = 0, n = args.length; i < n; i++) {
            results.push(args[i]);
        }
        return results;
    }
});

ayuta.logging.FirebugLogger = new ayuta.Class({
    superClasses: [ayuta.logging.Logger],
    initialize: function(category) {
        this.category = category;
    },
    _log: function(level, args) {
        var Level = ayuta.logging.Level;
        if (this.category) {
            console.group(this.category);
        }
        switch (level) {
        case Level.OFF:
            break;
        case Level.DEBUG:
            console.debug.apply(console, args);
            break;
        case Level.INFO:
            console.info.apply(console, args);
            break;
        case Level.WARN:
            console.warn.apply(console, args);
            break;
        case Level.ERROR:
            console.error.apply(console, args);
            break;
        }
        if (this.category) {
            console.groupEnd();
        }
    },
    _logException: function(level, e) {
        var args = [e.description, e];
        var Level = ayuta.logging.Level;
        if (this.category) {
            console.group(this.category);
        }
        switch (level) {
        case Level.OFF:
            break;
        case Level.DEBUG:
            console.debug.apply(console, args);
            break;
        case Level.INFO:
            console.info.apply(console, args);
            break;
        case Level.WARN:
            console.warn.apply(console, args);
            break;
        case Level.ERROR:
            console.error.apply(console, args);
            break;
        }
        if (this.category) {
            console.groupEnd();
        }
    }
});
